package com.lujianfei.mqtt.map

import android.content.Context
import android.util.AttributeSet
import android.view.ViewTreeObserver
import com.tencent.tencentmap.mapsdk.maps.MapView
import com.tencent.tencentmap.mapsdk.maps.TencentMapOptions

/**
 * @Author: wn
 * @Date: 2024/4/17 13:56
 * @Description: 自定义map  去掉 logo
 */
class TextureTMapView: MapView {
  // overLoad
  constructor(context: Context) : super(context)
  constructor(context: Context, options: TencentMapOptions?) : super(context, options)
  constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
  constructor(
    context: Context,
    attrs: AttributeSet?,
    options: TencentMapOptions?
  ) : super(context, attrs, options)

  constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
    context,
    attrs,
    defStyleAttr
  )

  constructor(
    context: Context,
    attrs: AttributeSet?,
    defStyleAttr: Int,
    options: TencentMapOptions?
  ) : super(context, attrs, defStyleAttr, options)


  init {
    this.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
      override fun onGlobalLayout() {
        //隐藏腾讯地图logo
        getChildAt(1)?.visibility = GONE
        viewTreeObserver.removeOnGlobalLayoutListener(this)
      }
    })
  }
}